<template>
  <Wrapper>
    <el-button type="primary" @click="exportZip">导出zip</el-button>
    <el-table :data="tableData">
      <el-table-column prop="date" label="Date" />
      <el-table-column prop="name" label="Name" />
      <el-table-column prop="address" label="Address" />
    </el-table>
  </Wrapper>
</template>

<script setup>
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]

function exportZip() {
  import('@/plugins/export-zip').then((zip) => {
    const tHeader = ['日期', '姓名', '地址']
    const filterVal = ['date', 'name', 'address']
    const data = formatJson(filterVal, tableData)
    zip.export_txt_to_zip(tHeader, data, '导出zip', '导出zip')
  })
}

function formatJson(filterVal, jsonData) {
  return jsonData.map((v) => filterVal.map((j) => v[j]))
}
</script>
